import requests
import json

# 创建会话
session = requests.Session()

# 发送目标请求
url = "https://xzcf.msa.gov.cn/cttic-egov-aps/apsStatistical/getCaseStatisticalList"
get_url = "https://xzcf.msa.gov.cn/cttic-egov-aps/components/caseDetail/getData?businessId=1C05C9DB73B947C7BC097715410DCDEA&businessType=3"
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer 6a0a7d0f-c768-4121-ae36-5bd87a895e18"
}

cookies = {
    'yfx_c_g_u_id_10000002':'_ck25022511240416235651637801741',
    'yfx_c_g_u_id_10000003':'_ck25022511240917122176567334057',
    'yfx_f_l_v_t_10000002':'f_t_1740453844608__r_t_1740453844608__v_t_1740469039717__r_c_0',
    'FSSO':'e80a0f2736819063f6efc956c84fa14e1b2a0bd02e0a5e8206cb0d125d53dd01c333fe546adc763d57a4ceab4b5a0b3bbe653f25c2f7bca86e47753ec416f4225d1952c6946f34e152aee5121d1ff41b9893de963be51c56f2c8b7fea7ccef9adb1fb2b1fcdcc465',
    'msa_token':'6a0a7d0f-c768-4121-ae36-5bd87a895e18',
    'yfx_f_l_v_t_10000003':'f_t_1740453849712__r_t_1740793299783__v_t_1740819265644__r_c_4',
    'access_token':'eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE3NDA4MTkyNjksImV4cCI6MTc0MDg0ODA2OSwic3ViIjoie1xuICBcInVzZXJJZFwiIDogXCI4NTU1NTcyNTAtMDEwMjAyMTQwMTAyMDUwNDA1MDFcIixcbiAgXCJwYXNzd29yZFwiIDogXCIkMmEkMTAkUnBGSmp4WWlYZEVzQUduV3AvOGZzT2V0TXVPT045Nk50ay9ZbTJNL1JLUnlVMEdac2VhRENcIixcbiAgXCJ1c2VyQ29kZVwiIDogXCIxNDIzMjIxOTg1MTIyNjcwMjktMDEwMjAyMTQwMTAyMDUwNDA1MDFcIixcbiAgXCJ1c2VyTmFtZUNuXCIgOiBcIuadjuWon1wiLFxuICBcImNsaWVudElwXCIgOiBcIlwiLFxuICBcImFwcElkXCIgOiBcIlwiL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Q3VycmVuY3lcIiA6IG51bGwsXG4gIFwib2ZmaWNlTWRtSWRcIiA6IG51bGwsXG4gIFwiY29ycE1kbUlkXCIgOiBudWxsLFxuICBcImNvcnBTaG9ydENvZGVcIiA6IG51bGwsXG4gIFwic3lzUm9sZUxpc3RcIiA6IG51bGwsXG4gIFwiZW5hYmxlZFwiIDogZmFsc2UsXG4gIFwiYXV0aG9yaXRpZXNcIiA6IFsgXSxcbiAgXCJhY2NvdW50Tm9uRXhwaXJlZFwiIDogZmFsc2UsXG4gIFwiYWNjb3VudE5vbkxvY2tlZFwiIDogZmFsc2UsXG4gIFwiY3JlZGVudGlhbHNOb25FeHBpcmVkXCIgOiBmYWxzZVxufSJ9.Vx1BE09SlsJ2IybtS90M-IFmPS6UQGQ4yyOLgcZXWvU'
}

data = {
    "generateBeginDate": "2025-01-15",
    "generateEndDate": "2025-03-12",
    'orgCode': "01020214",
    'orgCodeBool': 'true',
    'pageNo': 1,
    'pageSize':10000
}

try:
    response = session.post(url, headers=headers, json=data, cookies=cookies)
    response.raise_for_status()  # 检查响应状态码是否为 200
    #print("主表响应内容:", response.json())
    # 响应回来的参数
    strData = json.loads(response.text)
    strRecordsData = strData['data']['records']  # 获取到具体数据的位置
    print("写一个mysql新建表的语句，表名用为ywtg_ship_xingzhengchufa_23_43，表字段是默认字符串，要避免 Row size too large 错误，并翻译成中文注解插入表，",tuple(strRecordsData[0].keys()))

    response_info = session.get(get_url, headers=headers, cookies=cookies)
    response_info.raise_for_status()  # 检查响应状态码是否为 200
    #print("详情响应内容:", response_info.json())
    partiesDataText = json.loads(response_info.text)
    partiesList = partiesDataText['data']['caseReasonList'][0]['surveyReport']['partiesList']
    print("写一个mysql新建表的语句，表名用为ywtg_ship_xingzhengchufa_parties_23_43，表字段是默认字符串，要避免 Row size too large 错误，并翻译成中文注解插入表，",tuple(partiesList[0].keys()))

    enforceRecordList = partiesDataText['data']['caseReasonList'][0]['surveyReport']['enforceRecordList']
    print(
        "写一个mysql新建表的语句，表名用为ywtg_ship_xingzhengchufa_enforceRecord_23_43，表字段是默认字符串，要避免 Row size too large 错误，并翻译成中文注解插入表，",tuple(enforceRecordList[0].keys()))


except requests.exceptions.RequestException as e:
    print(f"请求失败: {e}")
    print("响应内容:", response.text)  # 打印原始响应内容